package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/20 15:23
 * @version  V1.0
 * @description:
 *
 */
func main() {

	var rect1 Rect = Rect{Point{1, 2}, Point{3, 4}}
	fmt.Println(rect1)

	//结构体内存分布是连续的
	//0xc000010400 0xc000010408 0xc000010410 0xc000010418
	fmt.Printf("%p %p %p %p\n", &rect1.leftUp.x, &rect1.leftUp.y, &rect1.rightDown.x, &rect1.rightDown.y)

	fmt.Println("---------------------------------")
	//若结构体字段是指针, 则指针本身占据的空间是连续的, 但是指针指向的空间不一定是连续的
	var rect2 Rect2 = Rect2{&Point{1, 2}, &Point{3, 4}}
	//0xc0000441f0 0xc0000441f8
	fmt.Printf("%p %p\n", &rect2.leftUp, &rect2.rightDown)
	//0xc00000a0d0 0xc00000a0d8 0xc00000a0e0 0xc00000a0e8 不一定,有可能一样
	fmt.Printf("%p %p %p %p\n", &rect2.leftUp.x, &rect2.leftUp.y, &rect2.rightDown.x, &rect2.rightDown.y)

}

type Point struct {
	x int
	y int
}

type Rect struct {
	leftUp, rightDown Point
}

type Rect2 struct {
	leftUp, rightDown *Point
}
